<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <link href="/css/bootstrap.min.css" rel="stylesheet">
    <link href="/css/font-awesome.css" rel="stylesheet">
    <link href="/css/datatables.min.css" rel="stylesheet">
    <link href="/css/animate.css" rel="stylesheet">
    <link href="/css/style.css" rel="stylesheet">
    <script src="/js/jquery-3.1.1.min.js"></script>
    <script src="/js/bootstrap.min.js"></script>
    <script src="/js/vue.js"></script>
    <style type = "text/css">
    .select{
        margin-top:0px;
        outline:none;
        border:1px solid #BBBBBB;
        border-radius:4px;
        position:relative;
        width:90px;
        display: inline-block;
    }
    .text{
    height:25px;
    text-align: center;
    -webkit-appearance:none;
    appearance:none;
    border:none;
    font-size:13px;
    padding:0px 10px;
    display:block;
    width:100%;
    -webkit-box-sizing:border-box;
    box-sizing:border-box;
    background-color:#FFFFFF;
    color:#333333;
    border-radius:4px;
    }
</style>
</head>
<body style="background-color:whitesmoke">
<div id="personnelTransfer">
<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-lg-10">
        <h2>人事调配</h2>
        <ol class="breadcrumb">
            <li>
                <a href="../../../templates/index.html">主页</a>
            </li>
            <li>
                <a>人事调配</a>
            </li>
            <li class="active">
                <strong>人事调配记录</strong>
            </li>
        </ol>
    </div>
</div>

<div class="wrapper wrapper-content animated fadeInRight">

    <div class="ibox-content m-b-sm border-bottom">
        <div class="row">

            <form role="form" class="form-horizontal">
                <div class="form-group">

                    <label class=" col-sm-2 control-label">员工编号</label>
                    <div class=" col-sm-2">
                        <input type="text" class="form-control" v-model="personnelTransferQuery.staffId" placeholder="请输入员工编号">
                    </div>

                    <label class=" col-sm-2 control-label">员工姓名</label>
                    <div class=" col-sm-2">
                        <input type="text" class="form-control" v-model="personnelTransferQuery.staffName" placeholder="请输入员工姓名">
                    </div>

                    <div>
                        <button class="btn btn-primary btn-sm" type="button"  @click="loadData()"><span class="glyphicon glyphicon-zoom-in" ></span> 查询</button>
                    </div>
                </div>
            </form>

        </div>
        <div class="select">
            <select class="text" v-model="personnelTransferQuery.order" @change="selectOrder" >
                <option value="0">按时间升序</option>
                <option value="1">按时间降序</option>
            </select>
        </div>

    </div>
    <div class="row">
        <div class="col-lg-12">

            <div class="ibox float-e-margins">

                <div class="ibox-content">

                    <table class="footable table table-stripped toggle-arrow-tiny" data-page-size="15">
                        <thead>
                        <tr>

                            <th data-toggle="true">员工编号</th>
                            <th data-toggle="true">员工姓名</th>
                            <th data-hide="phone">原部门</th>
                            <th data-hide="phone">原职务</th>
                            <th data-hide="phone">新部门</th>
                            <th data-hide="phone">新职务</th>
                            <th data-hide="phone">变动时间</th>
                            <th data-hide="phone">变动原因</th>
                            <th class="text-right" data-sort-ignore="true">操作</th>

                        </tr>
                        </thead>
                        <tbody>
                        <tr v-for="x in list">
                            <td>{{x.staffId}}</td>
                            <td>{{x.staffName}}</td>
                            <td>{{x.oldDepartment}}</td>
                            <td>{{x.oldJob}}</td>
                            <td>{{x.newDepartment}}</td>
                            <td>{{x.newJob}}</td>
                            <td>{{x.chengeTime}}</td>
                            <td>{{x.changeWhy}}</td>
                            <td class="text-right">
                                <button class="btn-primary btn btn-sm" @click="update(x)"><span class="glyphicon glyphicon-tag"></span> 编辑</button>
                                <button class="btn-primary btn btn-sm"  @click="del(x)"><span class="glyphicon glyphicon-trash"></span> 删除</button>
                            </td>
                        </tr>
                        </tbody>
                    </table>

                    <div>
                        一共{{total}}条数据,一共{{totalPage}}页,当前第{{curPage}}页
                        <button class="btn btn-success btn-sm" type="button" @click="prePages()">上一页</button>
                        <button class="btn btn-success btn-sm" type="button" @click="nextPages()">下一页</button>
                        <button class="btn btn-success btn-sm" type="button" @click="indexPage()">首页</button>
                        <button class="btn btn-success btn-sm" type="button" @click="endPage()">尾页</button>
                        跳转到<input type="number" id="num" style="width: 40px" min="1" max="10" v-model="selectPage" @keyup="valNum">页
                        <button class="btn btn-success btn-sm" type="button" @click="changePage()">跳转</button>
                        <select v-model="personnelTransferQuery.row" @change="selectRow" >
                            <option value="3">每页3条</option>
                            <option value="5">每页5条</option>
                            <option value="10">每页10条</option>
                        </select>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>

<!-- 模态框开始 -->
<div id="one" class="modal fade" style="top:100px">
    <div class="modal-dialog">

        <div class="modal-content">
            <!--头部-->
            <div class="modal-header">
                <h4 align="center">{{title}}</h4>

            </div>
            <!--主题内容-->
            <div class="modal-body">
                <form role="form" class="form-horizontal">
                    <input type="hidden" v-model="personnelTransfer.id">
                    <div class="form-group">
                        <label class=" col-sm-2 control-label">员工编号</label>
                        <div class=" col-sm-10">
                            <input type="text" disabled="disabled" class="form-control" v-model="personnelTransfer.staffId"  placeholder="请输入员工编号">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class=" col-sm-2 control-label">员工姓名</label>
                        <div class=" col-sm-10">
                            <input type="text" disabled="disabled" class="form-control" v-model="personnelTransfer.staffName"  placeholder="请输入员工姓名">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class=" col-sm-2 control-label">原部门</label>
                        <div class=" col-sm-10">
                            <input type="text" disabled="disabled" class="form-control" v-model="personnelTransfer.oldDepartment"  placeholder="请输入原部门">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class=" col-sm-2 control-label">原职务</label>
                        <div class=" col-sm-10">
                            <input type="text" disabled="disabled" class="form-control" v-model="personnelTransfer.oldJob"  placeholder="请输入原职务">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class=" col-sm-2 control-label">新部门</label>
                        <div class=" col-sm-10">
                            <select class="form-control" v-model="personnelTransfer.newDepartment" @change="changeDept()" >
                                <option v-for="y in depts" :value="y.deptName" selected>{{y.deptName}}</option>
                            </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class=" col-sm-2 control-label">新职务</label>
                        <div class=" col-sm-10">
                            <select class="form-control" v-model="personnelTransfer.newJob">
                                <option v-for="y in roles" :value="y" selected>{{y}}</option>
                            </select>
                        </div>
                    </div>


                    <div class="form-group">
                        <label class=" col-sm-2 control-label">调动原因</label>
                        <div class=" col-sm-10">
                            <input type="text" class="form-control" v-model="personnelTransfer.changeWhy"  placeholder="请输入调动原因">
                        </div>
                    </div>

                </form>
            </div>

            <!--底部-->
            <div class="modal-footer">
                <button class="btn btn-primary btn-sm" type="button" @click="closeWin()"><span class="glyphicon glyphicon-remove"></span>关闭</button>
                <button class="btn btn-primary btn-sm"  @click="saveAdmin"><span class="glyphicon glyphicon-save"></span>保存</button>
            </div>

        </div>
    </div>
</div>

</div>
</body>

<script>

    new Vue({
        el:"#personnelTransfer",
        data:{
            list:[],
            depts:[],
            roles:[],
            total:0,//总条数
            totalPage:0,//总页数
            selectPage:1,//选择页数
            personnelTransferQuery:{ //查询对象
                page:1,
                row:3,
                staffId:null,
                staffName:'',
                order:0
            },
            prePage:0,//上一页
            nextPage:0,//下一页.
            curPage:0,//当前页
            personnelTransfer:{
                id:0,
                staffId:"",
                staffName:"",
                oldDepartment:"",
                oldJob:"",
                newDepartment:"",
                newJob:"",
                /*changeTime:null,*/
                changeWhy:""
            },
            title:"添加"



        },
        methods:{
            loadData:function () {
                var self = this;
                $.ajax({
                    url:"/personnelTransfer/personnelTransferList",//请求地址
                    type:"get",
                    data:self.personnelTransferQuery,
                    dataType:"json",//返回的数据类型
                    success:function (data) {
                        self.list = data.list;
                        self.depts = data.depts;
                        self.total = data.total;
                        self.totalPage = data.totalPage;
                        self.prePage = data.prePage;
                        self.nextPage = data.nextPage;
                        self.curPage = data.curPage;
                    }

                })
            },
            prePages:function () {//上一页
                if(this.curPage>1){
                    this.personnelTransferQuery.page = this.prePage;
                    //刷新
                    this.loadData();
                }
            },
            nextPages:function () {
                if(this.curPage<this.totalPage){
                    this.personnelTransferQuery.page = this.nextPage;
                    //刷新
                    this.loadData();
                }

            },
            indexPage:function () {//首页
                this.personnelTransferQuery.page = 1
                //刷新
                this.loadData();

            },
            endPage:function () {//尾页
                this.personnelTransferQuery.page = this.totalPage;
                //刷新
                this.loadData();

            },
            changePage:function () {//跳转
                if(this.selectPage>this.totalPage){
                    this.personnelTransferQuery.page = this.totalPage;
                }else{
                    this.personnelTransferQuery.page = this.selectPage;
                }
                //刷新
                this.loadData();

            },
            selectRow:function () {//选择条数
                this.personnelTransferQuery.page=1
                //刷新
                this.loadData();

            },
            selectOrder:function(){//选择时间排序规则
                //刷新
                this.loadData();
            },
            changeDept:function(){
                var self = this;
                $.ajax({
                    url:"/personnelTransfer/roleList",//请求地址
                    type:"get",
                    data:{"p":self.personnelTransfer.newDepartment},
                    dataType:"json",//返回的数据类型
                    success:function (data) {
                        self.roles = data.roles;
                    }
                })
            },
            valNum:function () {
                //定义正则表达式对象
                var dd =/^[\u4e00-\u9fa5]{0,}$/
                //如果输入的汉字，就显示1
               if(dd.test(this.selectPage)) {
                   this.selectPage=1
               }else{
                   console.log("=="+this.selectPage)
                   //如果输入的值大于总页数，就回到最大值
                   if(this.selectPage>this.totalPage){
                       this.selectPage = this.totalPage;
                   }
               }


            },
            update:function(x) {//打开修改模态框
                $("#one").modal("show")
                //数据回显
                this.personnelTransfer.id = x.id;
                this.personnelTransfer.staffId = x.staffId;
                this.personnelTransfer.staffName = x.staffName;
                this.personnelTransfer.oldDepartment = x.oldDepartment;
                this.personnelTransfer.oldJob = x.oldJob;
                this.personnelTransfer.newDepartment = x.newDepartment;
                this.personnelTransfer.newJob = x.newJob;
                this.personnelTransfer.changeWhy = x.changeWhy;
                var self = this;
                $.ajax({
                    url:"/personnelTransfer/roleList",//请求地址
                    type:"get",
                    data:{"p":self.personnelTransfer.newDepartment},
                    dataType:"json",//返回的数据类型
                    success:function (data) {
                        self.roles = data.roles;
                    }
                })
                this.title="修改";

            },
            add :function () {//打开新增模态框
                $("#one").modal("show")
                this.title="添加";
                this.roles=[];
                //清空
                this.personnelTransfer.id=null;
                this.personnelTransfer.staffId=null;
                this.personnelTransfer.staffName=null;
                this.personnelTransfer.oldDepartment=null;
                this.personnelTransfer.oldJob=null;
                this.personnelTransfer.newDepartment=null;
                this.personnelTransfer.newJob=null;
                /*this.personnelTransfer.chengeTime=null;*/
                this.personnelTransfer.changeWhy=null;
            },
            del:function(x){
                flag = confirm("你确定要删除吗？");
                var self = this;
                if (flag){
                    $.ajax({
                        url:"/personnelTransfer/deletePersonnelTransfer",
                        type:"post",
                        contentType:"application/x-www-form-urlencoded",
                        data: {id:x.id},
                        dataType:"json",
                        success:function (data) {
                            alert(data.info);
                            if(data.info=="删除成功"){
                                //刷新
                                self.loadData();
                            }
                        }
                    })
                }
            },
            saveAdmin:function () {//保存
                var url="";
                if(this.title=="修改"){
                    url="/personnelTransfer/updatePersonnelTransfer";
                }else{
                    url="/personnelTransfer/addPersonnelTransfer";
                }
                var self = this;
                console.log(url);
                $.ajax({
                    url:url,
                    type:"post",
                    contentType:"application/x-www-form-urlencoded",
                    data:self.personnelTransfer,
                    dataType:"json",
                    success:function (data) {
                        console.log(data);
                        alert(data.info);
                        if(data.info=="保存成功"){
                            //关闭模态框
                            $("#one").modal("hide")
                            //刷新
                            self.loadData();
                        }
                    }
                })

            },
            closeWin:function () {//关闭模态框
                $("#one").modal("hide")
            }


        },
        mounted(){
            //运行loadData函数
            this.loadData();
        }
    })



</script>
</html>
